{% extends "cmdb/mbusiness/index.html" %}

{% block right_content %}
<div id="right_menu">
    <b class="modal-title">分类编辑</b>
    <hr/>
    <form class="form-horizontal">
        <div class="form-inline">
            <label for="id">分类id</label>
            <input class="form-control" style="width:300px;" type="text" id="id" value="{{ category_info.id }}" disabled/>
            <span style="display:none">*必填</span>
        </div><br />
        <div class="form-inline">
            <label for="categoryName">分类名</label>
            <input class="form-control" style="width:300px;" type="text" id="categoryName" value="{{ category_info.category_name }}" />
            <span style="color:red">*必填</span>
        </div><br />
        <div class="form-inline">
            <label>父分类</label>
            <select class="form-control" id="parentLevel" style="width:300px;" >
                <option  value="0:0"></option>
                {% if category_list %}
                {% for singleV in category_list %}
                    <option  value="{{ singleV.grade }}:{{ singleV.id }}" {% ifequal singleV.id category_info.parent_category  %} selected {% endifequal %}>{{ singleV.caterogy_level }} — {{ singleV.category_name }}</option>
                {% endfor %}
                {% endif %}
            </select>
            <span style="display:none;">*必填</span>
        </div><br />
        <div class="form-inline" style="padding-left:12px">
            <label for="comment">备注</label>
            <input class="form-control" style="width:300px;" type="text" id="comment" value="{{ category_info.comment }}" />
            <span style="display:none"><font color="red">*</font>必填</span>
        </div><br />
        <input type="text" id="operator" value="{{ request.session.username }}" style="display: none;">
    </form>
    <div style="padding-left: 100px;">
        <button type="button" class="btn btn-primary" id="item_edit">
            确定
        </button>&nbsp;&nbsp;&nbsp;
        <button type="button" class="btn btn-default" id="edit_cancel">
            取消
        </button>
    </div>
</div>

<script type="text/javascript">
$("#item_edit").click(function(){
    var id =  $("#id").val();
    var categoryName = $("#categoryName").val();
    if(!categoryName || categoryName == ''){
        alert('分类名不能为空');
        return;
    }
    var parentLevel = $("#parentLevel").val();
    var comment = $("#comment").val();
    var operator = $("#operator").val();
    var urls = "{% url 'business:ceditaction' %}";
    var postdata = {id:id,category_name:categoryName, parent_category:parentLevel, comment:comment, operator:operator}
    var jsonstr = $.ajax({
			url : urls,
			type : "POST",
			data : postdata,
			async : false,
			cache : false
		});
	var jsonobj = eval('(' + jsonstr.responseText + ')');
	if(jsonobj.status == 0){
	    alert(jsonobj.message);
	}else{
	    window.location.href="{% url 'business:home' %}?page=" + {{ page }};
	}
});

$("#edit_cancel").click(function(){
    window.location.href="{% url 'business:home' %}?page=" + {{ page }};
});
</script>
{% endblock %}